const initialState = {
  userInfo: {} as UserInfoType,
  user: {} as UserType,
};

export type ActionType =
  | { type: 'user/saveUserInfo'; payload: UserInfoType }
  | { type: 'user/saveUser'; payload: UserType };

export default function userReducer(state = initialState, action: ActionType): typeof initialState {
  switch (action.type) {
    case 'user/saveUserInfo':
      return {
        ...state,
        userInfo: action.payload,
      };

    case 'user/saveUser':
      return {
        ...state,
        user: action.payload,
      };
    default:
      return state;
  }
}

interface UserInfoType {
  id: string;
  name: string;
  photo: string;
  art_count: number;
  follow_count: number;
  fans_count: number;
  like_count: number;
}

export interface UserType {
  id: string;
  photo: string;
  name: string;
  mobile: string;
  gender: number;
  birthday: string;

  intro: string;
}
